const Service = require("egg").Service;

class OrderService extends Service {

    async getList() {
        const { ctx, app } = this;
        let {
            pageIndex,
            pageSize,
            tit,
            state
        } = ctx.request.body;
        let sql = "select * from infos where id=id "
        if (tit) {
            sql += `and tit like "%${tit}%" `
        }

        if (state !== undefined) {
            sql += `and status like "%${state}%" `
        }
        let res = await app.mysql.query(sql);
        let data = res.slice((pageIndex - 1) * pageSize, pageIndex * pageSize);
        return {
            total: res.length,
            data
        }
    }
    //删除
    async del() {
        const { ctx, app } = this;
        const { id } = JSON.parse(ctx.query.params);

        let res = await app.mysql.delete("infos", { id });
        return res;
    }
    //编辑
    async edit() {
        const { ctx, app } = this;
        let {
            name,
            tit,
            status,
            id
        } = ctx.request.body;

        let res = await app.mysql.update("infos", {
            name,
            tit,
            status,
            id
        })
        console.log(res);
        return res
    }
}
module.exports = OrderService;